Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As Long, ByVal nIndex As Long) As Long
Private Declare Function ResizePalette Lib "gdi32" (ByVal hPalette As Long, ByVal nNumEntries As Long) As Long
Private Declare Function SetPaletteEntries Lib "gdi32" (ByVal hPalette As Long, ByVal wStartIndex As Long, ByVal wNumEntries As Long, lpPaletteEntries As PALETTEENTRY) As Long
Private Declare Function GetSystemPaletteEntries Lib "gdi32" (ByVal hdc As Long, ByVal wStartIndex As Long, ByVal wNumEntries As Long, lpPaletteEntries As PALETTEENTRY) As Long
Private Const PALETTE_INDEX = &H1000000
Private Const NO_COLOR = -1
Private LogicalPalette As Long
Private SysPalSize As Integer
Private NumStaticColors As Integer
Private SelectedI As Integer
Private SelectedJ As Integer
Private SelectedColor As Integer
Private SelectedR As Integer
Private SelectedG As Integer
Private SelectedB As Integer
Private dx As Integer
Private dy As Integer
' Load the Pict palette with PC_EXPLICIT entries
' so they match the system palette.
Private Sub LoadSystemPalette()
Dim palentry(0 To 255) As PALETTEENTRY
Dim i As Integer
' Make the logical palette as big as possible.
LogicalPalette = picCanvas.Picture.hPal
If ResizePalette(LogicalPalette, SysPalSize) = 0 Then
MsgBox "Error resizing the palette."
End
End If
' Flag all palette entries as PC_EXPLICIT.
' Set peRed to the system palette indexes.
For i = 0 To SysPalSize - 1
palentry(i).peRed = i
palentry(i).peFlags = PC_EXPLICIT
Next i
' Update the palette (ignore return value).
i = SetPaletteEntries(LogicalPalette, 0, SysPalSize, palentry(0))
End Sub
' Fill the system picture with all the palette
' colors, hatching the static colors.
Private Sub ShowColors()
Dim i As Integer
Dim j As Integer
Dim clr As Integer
Dim oldfill As Integer
Dim olddraw As Integer
picCanvas.Cls
' Display the colors using palette indexing.
dx = picCanvas.ScaleWidth / 16
dy = picCanvas.ScaleHeight / 16
clr = 0
For i = 0 To 15
For j = 0 To 15
picCanvas.Line (j * dx, i * dy)-Step(dx, dy), _
clr + PALETTE_INDEX, BF
clr = clr + 1
Next j
Next i
' Hatch the static colors.
oldfill = picCanvas.FillStyle
olddraw = picCanvas.DrawMode
picCanvas.FillStyle = vbDownwardDiagonal
picCanvas.DrawMode = vbInvisible
picCanvas.Line (0, 0)-Step((NumStaticColors \ 2) * dx - 1, dy - 1), , B
picCanvas.Line (j * dx, i * dy)-Step(-(NumStaticColors \ 2) * dx, -dy), , B
picCanvas.FillStyle = oldfill
picCanvas.DrawMode = olddraw
' Highlight the previously selected color.
SelectedColor = NO_COLOR
SelectColor SelectedI, SelectedJ
End Sub
' Select the color at the indicated position.
Private Sub SelectColor(ByVal i As Integer, ByVal j As Integer)